import { computed, inject, unref,type Ref } from 'vue'
import { formContextKey } from "../../tokens";
import { useProp } from "../use-prop";
type MaybeRef<T> = T | Ref<T>;

export const useDisabled = (fallback?: MaybeRef<boolean>) => {
  const disabled = useProp<boolean>('disabled')
  const form = inject(formContextKey, undefined)
  return computed(
    () => (disabled.value || unref(fallback) || form?.props?.disabled || false) as boolean
  )
}
